import { createSlice } from "@reduxjs/toolkit";

const counterStore = createSlice({
    name:'counter',
    //初始化state
    initialState:{
        count:0
    },
    //修改状态的方法  同步方法,  支持直接修改
    reducers:{
        inscremment(state){
            state.count++
        },
        decrement(state){
            state.count--
        },
        addToNum(state,action){
            state.count += action.payload
        }
    }
})

//结构出来的方法 actionCreater函数
const { inscremment,decrement,addToNum } = counterStore.actions
//导出reducer
const reducer = counterStore.reducer

//按需导出actionCreater函数
export { inscremment,decrement,addToNum }
//导出reducer
export default reducer
